package cn.gson.crmdemo.model.service;

import java.math.BigDecimal;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSONArray;

import cn.gson.crmdemo.model.dao.CkDao;
import cn.gson.crmdemo.model.dao.CpDao;
import cn.gson.crmdemo.model.dao.SupplierDao;
import cn.gson.crmdemo.model.mapper.CpMapper;
import cn.gson.crmdemo.model.pojo.Product;
import cn.gson.crmdemo.model.pojo.Supplier;
import cn.gson.crmdemo.model.pojo.Warehouse;
import cn.gson.crmdemo.model.vo.FpVo;

@Service
@Transactional(rollbackFor=Exception.class)

public class CpService {
	@Autowired
	CpDao Cp;
	@Autowired
	CkDao ckdao;
	@Autowired
	CpMapper Cp2;
	@Autowired
	SupplierDao sdao;
	/*
	 * 查询所有产品信息
	 */
	public JSONArray selectProduct() {
		return Cp2.selectProduct();
	}
	/*
	 * 查询所有供应商
	 */
	public JSONArray selectSupplier() {
		return Cp2.selectSupplier();
	}
	/*
	 * 查询供应商商品
	 */
	public JSONArray selectSupplierGys(Integer gysId) {
		return Cp2.selectSupplierGys(gysId);
	}
	/*
	 * 新增产品
	 */
	public void addProudct(String cpName,BigDecimal cpPrice,Integer gysId) {
		Product p = new Product();
		Supplier supplier = sdao.findById(gysId).get();
		p.setCpName(cpName);
		p.setCpPrice(cpPrice);
		p.setGysId(supplier);
		Cp.save(p);
	}
	
	/*
	 *  修改产品状态
	 */
	public void xg(Integer cpId) {
		Product p = Cp.findById(cpId).get();
		p.setCpState(1);
	}
}
